package com.yujistu.fragment.appointfragment.couseadapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yujistu.R;
import com.yujistu.adapter.BaseListAdapter;
import com.yujistu.global.Constants;
import com.yujistu.integration.result.EnterResult;

import java.util.ArrayList;

/**
 * Created by Win on 2015/11/16.
 */
public class EnterpriseAdapter extends BaseListAdapter<EnterResult>{

    public EnterpriseAdapter(Context context) {
        super(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    protected View getRealView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder  holder = null;
        if(convertView == null){
            convertView = mInflater.inflate(R.layout.view_enter_prise_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        EnterResult   result = mDatas.get(position);
        if(!TextUtils.isEmpty(result.getImage())){
            Glide.with(mContext.getApplicationContext()).load(result.getImage()).crossFade().centerCrop().into(holder.image);
        }

        if(!TextUtils.isEmpty(result.getName())){
            holder.title.setText(result.getName());
        }

        if(!TextUtils.isEmpty(result.getPrice())){
            holder.haveTV.setText(Constants.DOLLAR_SIGN + result.getPrice());
        }

        if(!TextUtils.isEmpty(result.getQuantity())){
            holder.priceTV.setText(result.getQuantity() + "企业已购");
        }

        return convertView;
    }

    public class ViewHolder extends BaseViewHolder{

        public ImageView  image;
        public TextView   title;
        public TextView   haveTV;
        public TextView   priceTV;

        public ViewHolder(View view) {
            super(view);

            image = (ImageView) view.findViewById(R.id.enterIV);
            title = (TextView) view.findViewById(R.id.enterTV);
            haveTV = (TextView) view.findViewById(R.id.enterpriseTV);
            priceTV = (TextView) view.findViewById(R.id.have_payTV);
        }
    }
}
